package com.servlet.test;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        // 从表单中获取的用户名和密码与预定义的用户名和密码进行比较
        String[] login = RegisServlet.login(req);
        String predefinedUsername  = login[0];
        String predefinedPassword = login[1];

        if (username != null && password != null && username.equals(predefinedUsername) && password.equals(predefinedPassword)) {
            System.out.println("登录成功");
        } else {
            System.out.println("登录失败");
        }
    }
}